#pragma once

#include "resource.h"
#include "SimpleString.hpp"

class CNotifyIcon
{
public:
	static CNotifyIcon &GetInstance()
	{
		static CNotifyIcon notifyIcon;
		return notifyIcon;
	}

	void CreateNotifyIcon(HINSTANCE hInst, HWND hWnd)
	{
		// {F8C09103-564E-456F-9DBA-DC505C288901}
		static const GUID niGuid = { 0xf8c09103, 0x564e, 0x456f, { 0x9d, 0xba, 0xdc, 0x50, 0x5c, 0x28, 0x89, 0x1 } };
		
		m_notifyIconData.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_WINTCY));
		m_notifyIconData.uCallbackMessage = WM_USER + 1;
		m_notifyIconData.hWnd = hWnd;		
		m_notifyIconData.guidItem = niGuid;
		_tcscpy_s(m_notifyIconData.szTip, ARRAYSIZE(m_notifyIconData.szTip),
			SimpleString::LoadFromResource(hInst, IDS_APP_TITLE).ToCharArray());
		m_notifyIconData.uFlags = NIF_GUID | NIF_ICON | NIF_TIP | NIF_MESSAGE;

		m_bIsCreated = (TRUE == Shell_NotifyIcon(NIM_ADD, &m_notifyIconData));
	}

	bool ChangeIcon(HICON hIcon)
	{
		if (!m_bIsCreated)
		{
			return false;
		}

		m_notifyIconData.hIcon = hIcon;
		return TRUE == Shell_NotifyIcon(NIM_MODIFY, &m_notifyIconData);
	}
	
	~CNotifyIcon()
	{
		if (m_bIsCreated)
		{
			m_bIsCreated = (TRUE == Shell_NotifyIcon(NIM_DELETE, &m_notifyIconData)) ? true : false;
		}
	}

private:
	CNotifyIcon()
	{
		SecureZeroMemory(&m_notifyIconData, sizeof(m_notifyIconData));
	}

	CNotifyIcon(CNotifyIcon const&);
	void operator=(CNotifyIcon const&);

	NOTIFYICONDATA m_notifyIconData;
	bool m_bIsCreated;
};
